/**
 *  iBizSys 5.0 机器人生产代码（不要直接修改当前代码）
 *  http://www.ibizsys.net
 */
package com.sa.ibiz.demo.srv.demo.service;


import java.util.ArrayList;
import java.util.List;

import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.annotation.PostConstruct;
import net.ibizsys.paas.service.ServiceGlobal;
import net.ibizsys.paas.util.StringHelper;
import net.ibizsys.paas.core.IDataEntity;
import net.ibizsys.paas.data.DataObject;
import net.sf.json.JSONObject;
import net.ibizsys.paas.service.IService;
import net.ibizsys.paas.service.IInheritDEServiceProxy;
import org.springframework.stereotype.Component;

import com.sa.ibiz.demo.srv.demo.entity.IBZ5HARDWARE;
import com.sa.ibiz.demo.srv.demo.dao.IBZ5HARDWAREDAO;

import com.sa.ibiz.demo.srv.demo.service.IBZ5StorageService;
import com.sa.ibiz.demo.srv.demo.entity.IBZ5Storage;
import com.sa.ibiz.demo.srv.demo.service.IBZ5CPUService;
import com.sa.ibiz.demo.srv.demo.entity.IBZ5CPU;
/**
 * 继承实体[IBZ5HARDWARE]服务操作对象
 */
@Component
public class IBZ5HARDWAREServiceProxy extends IBZ5HARDWAREService<IBZ5HARDWARE> implements IInheritDEServiceProxy<IBZ5HARDWARE> {

    private static final Log log = LogFactory.getLog(IBZ5HARDWAREServiceProxy.class);
    public IBZ5HARDWAREServiceProxy() {
        super();

    }
    /**
     * Spring注册后执行构造处理
     * @throws Exception
     */
    @PostConstruct
    public void postConstruct() throws Exception {
        ServiceGlobal.registerService(getServiceId(), this);
        ServiceGlobal.registerService(getServiceId()+"Proxy", this);
    }

    /* (non-Javadoc)
     * @see net.ibizsys.paas.service.ServiceBase#getServiceId()
     */
    @Override
    protected String getServiceId() {
        return "com.sa.ibiz.demo.srv.demo.service.IBZ5HARDWAREService";
    }

    /* (non-Javadoc)
     * @see net.ibizsys.paas.service.ServiceBase#remove(net.ibizsys.paas.entity.IEntity)
     */
    @Override
    public void remove(IBZ5HARDWARE entity) throws Exception {
        if(entity.getIBZ5HARDWAREType()==null) {
            //重新获取
            this.get(entity);
        }

        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"Storage",true)==0) {
            IBZ5StorageService realService= (IBZ5StorageService)ServiceGlobal.getService(IBZ5StorageService.class,this.getSessionFactory());
            IBZ5Storage realEntity = new  IBZ5Storage();
            realEntity.setIBZ5StorageId(entity.getIBZ5HARDWAREId());
            realService.remove(realEntity );
            return;
        }
        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"CPU",true)==0) {
            IBZ5CPUService realService= (IBZ5CPUService)ServiceGlobal.getService(IBZ5CPUService.class,this.getSessionFactory());
            IBZ5CPU realEntity = new  IBZ5CPU();
            realEntity.setIBZ5CPUId(entity.getIBZ5HARDWAREId());
            realService.remove(realEntity );
            return;
        }

        throw new Exception(StringHelper.format("无法识别的继承类型[%1$s]",entity.getIBZ5HARDWAREType()));
    }

    /* (non-Javadoc)
     * @see net.ibizsys.paas.service.IInheritDEServiceProxy#getReal(net.ibizsys.paas.entity.IEntity, boolean)
     */
    @Override
    public IBZ5HARDWARE getReal(IBZ5HARDWARE entity,boolean bTryMode) throws Exception {
        if(entity.getIBZ5HARDWAREType()==null) {
            //重新获取
            if(!this.get(entity,bTryMode))
                return null;
        }

        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"Storage",true)==0) {
            IBZ5StorageService realService= (IBZ5StorageService)ServiceGlobal.getService(IBZ5StorageService.class,this.getSessionFactory());
            IBZ5Storage realEntity = new  IBZ5Storage();
            realEntity.setIBZ5StorageId(entity.getIBZ5HARDWAREId());
            if(! realService.get(realEntity,bTryMode ))
                return null;
            return realEntity;
        }
        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"CPU",true)==0) {
            IBZ5CPUService realService= (IBZ5CPUService)ServiceGlobal.getService(IBZ5CPUService.class,this.getSessionFactory());
            IBZ5CPU realEntity = new  IBZ5CPU();
            realEntity.setIBZ5CPUId(entity.getIBZ5HARDWAREId());
            if(! realService.get(realEntity,bTryMode ))
                return null;
            return realEntity;
        }

        throw new Exception(StringHelper.format("无法识别的继承类型[%1$s]",entity.getIBZ5HARDWAREType()));
    }

    /* (non-Javadoc)
     * @see net.ibizsys.paas.service.IInheritDEServiceProxy#getRealService(net.ibizsys.paas.entity.IEntity)
     */
    @Override
    public IService getRealService(IBZ5HARDWARE entity) throws Exception {
        if(entity.getIBZ5HARDWAREType()==null) {
            //重新获取
            this.get(entity);
        }

        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"Storage",true)==0) {
            IBZ5StorageService realService= (IBZ5StorageService)ServiceGlobal.getService(IBZ5StorageService.class,this.getSessionFactory());
            return realService;
        }
        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"CPU",true)==0) {
            IBZ5CPUService realService= (IBZ5CPUService)ServiceGlobal.getService(IBZ5CPUService.class,this.getSessionFactory());
            return realService;
        }

        throw new Exception(StringHelper.format("无法识别的继承类型[%1$s]",entity.getIBZ5HARDWAREType()));
    }

    /* (non-Javadoc)
     * @see net.ibizsys.paas.service.ServiceBase#onExportCurModel(net.ibizsys.paas.entity.IEntity, java.util.ArrayList)
     */
    @Override
    protected void onExportCurModel(IBZ5HARDWARE entity,  ArrayList<JSONObject> list)throws Exception {
        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"Storage",true)==0) {
            IBZ5StorageService realService= (IBZ5StorageService)ServiceGlobal.getService(IBZ5StorageService.class,this.getSessionFactory());
            IBZ5Storage realEntity = new  IBZ5Storage();
            realEntity.setIBZ5StorageId(entity.getIBZ5HARDWAREId());
            realService.exportModel(realEntity,list );
            return;
        }
        if(StringHelper.compare(entity.getIBZ5HARDWAREType(),"CPU",true)==0) {
            IBZ5CPUService realService= (IBZ5CPUService)ServiceGlobal.getService(IBZ5CPUService.class,this.getSessionFactory());
            IBZ5CPU realEntity = new  IBZ5CPU();
            realEntity.setIBZ5CPUId(entity.getIBZ5HARDWAREId());
            realService.exportModel(realEntity,list );
            return;
        }
        throw new Exception(StringHelper.format("无法识别的继承类型[%1$s]",entity.getIBZ5HARDWAREType()));
    }

}